package com.asiainfo.util;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Web层相关的实用工具类
 * 
 * @author luhf
 * @date 2013-1-13 下午7:48:00
 */
public class WebUtil{

	private static final Logger log=LoggerFactory.getLogger(WebUtil.class);

	static{
		log.debug("启动web工具类!");
	}

	/**
	 * 私用构造主法.因为此类是工具类.
	 */
	public WebUtil(){
		super();
	}

	/**
	 * @title 将请求参数封装为Map<br>
	 *        request中的参数t1=1&t1=2&t2=3<br>
	 *        形成的map结构：<br>
	 *        key=t1;value[0]=1,value[1]=2<br>
	 *        key=t2;value[0]=3<br>
	 * @param request
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public static HashMap<String,String> getPraramsAsMap(HttpServletRequest request){
		HashMap<String,String> hashMap=new HashMap<String,String>();
		Map map=request.getParameterMap();
		Iterator keyIterator=(Iterator)map.keySet().iterator();
		while(keyIterator.hasNext()){
			String key=(String)keyIterator.next();
			String value=((String[])(map.get(key)))[0];
			hashMap.put(key,value);
		}
		return hashMap;
	}
}
